package com.hualan.sfzy.service.course.serviceimpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hualan.sfzy.constant.CommonConstant;
import com.hualan.sfzy.entity.course.CourseEvaluate;
import com.hualan.sfzy.mapper.course.CourseEvaluateMapper;
import com.hualan.sfzy.service.course.CourseEvaluateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CourseEvaluateServiceImpl implements CourseEvaluateService {
    @Autowired
    private CourseEvaluateMapper courseEvaluateMapper;
    @Override
    public int add(CourseEvaluate courseEvaluate) {
        return courseEvaluateMapper.insert(courseEvaluate);
    }

    @Override
    public int remove(Integer id) {
        return courseEvaluateMapper.delete(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return courseEvaluateMapper.deleteBatch(ids);
    }

    @Override
    public int edit(CourseEvaluate courseEvaluate) {
        return courseEvaluateMapper.update(courseEvaluate);
    }

    @Override
    public List<CourseEvaluate> find() {
        return courseEvaluateMapper.select(null);
    }

    @Override
    public CourseEvaluate findById(Integer id) {
        return courseEvaluateMapper.selectById(id);
    }

    @Override
    public Map<String, Object> findByPage(Integer pageNum, Integer pageSize, CourseEvaluate courseEvaluate) {
        PageHelper.startPage(pageNum, pageSize);
        List<CourseEvaluate> list = courseEvaluateMapper.select(courseEvaluate);
        PageInfo<CourseEvaluate> pageInfo = new PageInfo<CourseEvaluate>(list);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put(CommonConstant.PAGE_LIST, list);
        map.put(CommonConstant.PAGE_TOTAL, pageInfo.getPages());
        map.put(CommonConstant.TOTAL, pageInfo.getTotal());
        return map;
    }

    @Override
    public int countByCourseId(Integer courseId) {
        return courseEvaluateMapper.countByCourseId(courseId);
    }
}

